//
//  TLNotification.m
//  TLLayout
//
//  Created by Tianlong on 2017/9/15.
//  Copyright © 2017年 Tianlong. All rights reserved.
//

#import "TLNotification.h"

@interface TLNotification ()
@property (nonatomic , copy) CallBackBlock callBackBlock;
@property (nonatomic , assign) SEL selector;
@property (nonatomic , copy) NSString *noteName;
@property (nonatomic , strong) id anyObject;
@end

@implementation TLNotification

+(instancetype)addObserver:(id)observer selector:(SEL)aSelector name:(NSNotificationName)aName object:(id)anObject{
    TLNotification *noteTool = [[TLNotification alloc] init];
    noteTool.noteName = aName;
    noteTool.selector = aSelector;
    noteTool.anyObject = anObject;
    [[NSNotificationCenter defaultCenter] addObserver:noteTool selector:aSelector name:aName object:anObject];
    return noteTool;
}

+(instancetype)addObserver:(id)observer name:(NSNotificationName)aName object:(id)anObject callBackBlock:(CallBackBlock)callBack{
    TLNotification *noteTool = [[TLNotification alloc] init];
    noteTool.noteName = aName;
    noteTool.callBackBlock = callBack;
    noteTool.anyObject = anObject;
    [[NSNotificationCenter defaultCenter] addObserver:noteTool selector:@selector(noteCallBack:) name:aName object:anObject];
    return noteTool;
}

-(void)noteCallBack:(NSNotification *)note{
    if (self.callBackBlock) {
        self.callBackBlock(note);
    }
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:self.noteName object:self.anyObject];
}

@end
